package com.miyu.system.controller.opensystem;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.miyu.system.service.opensystem.OpenSystemService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * opensystem
 *
 * @author longm
 * @date 2022/09/29
 */
@RestController
@RequestMapping(value = "/open-system")
public class OpenSystem {

    @Resource
    private OpenSystemService openSystemService;

    /**
     * 得到天气
     * @param param 参数
     * @return {@link JSONObject}
     * @throws Exception 例外
     */
    @RequestMapping("weather")
    public JSONObject getWeather(@RequestBody JSONObject param) throws Exception {
        String vCity = "";
        if(!param.containsKey("version")){
            param.put("version","v1");
            vCity+="v1";
        }else {
            vCity+=param.getString("version");
        }
        if(!param.containsKey("city")){
            /*默认北京*/
            param.put("city","101010100");
            vCity+="101010100";
        }else {
            vCity+=param.getString("city");
        }
        param.put("vCity",vCity);
        return openSystemService.getWeather(param);
    }

    /**
     * 查询系统城市
     * @return {@link JSONArray}
     */
    @RequestMapping("querySysCity")
    public JSONArray querySysCity(){
        return openSystemService.querySysCity();
    }
}
